package com.example.administrator.spritelgs;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import static com.example.administrator.spritelgs.R.id.EtPsw;
import static com.example.administrator.spritelgs.R.id.EtUsr;

public class loginActivity extends Activity {

    EditText etUsr;
    EditText etPsw;
    Button btnLogin;
    Button btnLogout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        initUI();
    }

    /*
    初始化控件
     */
    private void initUI(){
        etUsr = (EditText)findViewById(EtUsr);
        etPsw = (EditText)findViewById(EtPsw);

        btnLogin = (Button)findViewById(R.id.BtnLogin);
        //添加点击事件
        btnLogin.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                String usr = etUsr.getText().toString();
                String psw = etPsw.getText().toString();
                if(usr.equals(""))
                    Toast.makeText(getApplicationContext(), "账号名不能为空", Toast.LENGTH_SHORT).show();
                else if(psw.equals(""))
                    Toast.makeText(getApplicationContext(), "密码不能为空",Toast.LENGTH_SHORT).show();
                else if(usr.length()<5)
                    Toast.makeText(getApplicationContext(), "账号至少5位",Toast.LENGTH_SHORT).show();
                else if(psw.length()<3)
                    Toast.makeText(getApplicationContext(), "密码至少3位",Toast.LENGTH_SHORT).show();
                else if(usr.equals("admin") && psw.equals("123")) {
                    Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
                    //跳转到主界面
                    Intent intent = new Intent();//创建意图
                    /*
                    设置出发点及终点
                    */
                    intent.setClass(getApplicationContext(), gameActivity.class);
                    //执行意图
                    startActivity(intent);
                }
                else
                    Toast.makeText(getApplicationContext(), "用户名或密码错误",Toast.LENGTH_SHORT).show();
            }
        });

        btnLogout = (Button) findViewById(R.id.BtnLogout);
        //添加点击事件
        btnLogout.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Toast.makeText(getApplicationContext(), "登出", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
